// pages/i_addrS/i_addrS.js
const app = getApp()
var get_saddr;var del_user_addr;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    del_user_addr = app.data.ucenter_url + 'del_user_addr';
  },
  xztap:function(e){
    var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    var mobile = e.currentTarget.dataset.mobile;
    var area = e.currentTarget.dataset.area;
    var shi = area.split('/');
    var city = shi[1];
    var addr = e.currentTarget.dataset.addr;
    app.data.s_id= id;
    app.data.sname = name;
    app.data.smobile = mobile;
    app.data.sarea = area;
    app.data.scity = city;
    app.data.saddr = addr;
    wx.navigateBack({
      delta: 1,
    })
  },
  bjtap:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    var type = e.currentTarget.dataset.type;
    wx.redirectTo({
      url: '/pages/i_addressxq/i_addressxq?id='+id+'&type='+type,
    })
  },
  deltap:function(e){
    var that = this;
    var list = that.data.list;
    var id = e.currentTarget.dataset.id;
    var index = e.currentTarget.dataset.index;
    wx.showModal({
      title: '提示',
      content: '是否确认删除？',
      showCancel: true,
      success:function(e){
        if(e.confirm){
          wx.request({
            url: del_user_addr,
            data: {
              id:id
            },
            header: {
              'content-type': 'application/json' // 默认值
            },
            success(res) {
              console.log(res.data);
              if(res.data.state == 1){
                list.splice(index,1);
                that.setData({
                  list:list
                })
                wx.showModal({
                  title: '提示',
                  content: '删除成功！',
                  showCancel: false
                })
              }else{
                wx.showModal({
                  title: '提示',
                  content: res.data.msg,
                  showCancel: false
                })
              }
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var aid = wx.getStorageSync('uid');
    get_saddr = app.data.index_url + 'get_saddr';
    wx.request({
      url: get_saddr,
      data: {
        uid:aid
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data);
        var list = res.data.list;
        that.setData({
          list:list
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})